﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Cors;
using XQ.Framework.core;
using XQ.WeChatOfficialAccount.BLL.Sys;
using XQ.WeChatOfficialAccount.DAL;
using XQ.WeChatOfficialAccount.WebAPI.Filter;

namespace XQ.WeChatOfficialAccount.WebAPI.Controllers.System
{
    /// <summary>
    /// 菜单相关
    /// </summary>
    //[FormAuthenticationFilter]
    public class MenuController : ApiController
    {
        [Route("Api/Menu/MenuJson")]
        public string MenuJson()
        {
            return MenuBll.Instance.GetMenuJson();
        }

        /// <summary>
        /// 删除菜单接口
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("Api/Menu/DelMenu")]
        public string DelMenu(int id)
        {
            return MenuBll.Instance.DeleteMenu(id);
        }

        [Route("Api/Menu/UpdateMenu")]
        public string UpdateMenu([FromBody]Sys_Menus model)
        {
            int id = model.ID;
            string name = model.MenuName;
            string url = model.Linkurl;
            int sortnum = (int)model.Sortnum;
            bool isvisible = model.IsVisible == true;
            //int parentid = ConvertHelper.getInt(this.X.GET("parentid"), -1);
            string navtag = model.NavTag;
            string iconcls = model.iconCls;
            string iconurl = model.iconUrl;
            string bigimageurl = model.BigImageUrl;
            bool IsRefresh = model.IsRefresh == true;
            string InvokingMothed = model.InvokingMothed;
            string component = model.Component;
            return MenuBll.Instance.UpdateMenu(id, name, url, sortnum, isvisible, navtag, iconcls, iconurl, bigimageurl, IsRefresh, InvokingMothed, component);
        }

        /// <summary>
        /// 添加菜单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [Route("Api/Menu/AppendMenu")]
        [HttpPost]
        public string AppendMenu([FromBody]Sys_Menus model)
        {
            int? parentId = model.ParentID == 0 ? null : model.ParentID;
            string name = model.MenuName;
            string url = model.Linkurl;
            int? sortnum = model.Sortnum;
            bool isvisible = model.IsVisible == true;
            //int parentid = ConvertHelper.getInt(this.X.GET("parentid"), -1);
            string navtag = model.NavTag;
            string iconcls = model.iconCls;
            string iconurl = model.iconUrl;
            string bigimageurl = model.BigImageUrl;
            bool IsRefresh = model.IsRefresh == true;
            string InvokingMothed = model.InvokingMothed;
            string component = model.Component;
            return MenuBll.Instance.AddMenu(name, url, sortnum, isvisible, parentId, navtag, iconcls, iconurl, bigimageurl, IsRefresh, InvokingMothed, component);
        }

        /// <summary>
        /// 根据菜单ID获取菜单详情
        /// </summary>
        /// <param name="id">菜单ID</param>
        /// <returns></returns>
        [Route("Api/Menu/GetMenuByID")]
        public Sys_Menus GetMenuByID(int id)
        {
            return new MenuBll().GetMenuByID(id);
        }
    }
}